(define (square x) (* x x))

(define (sum-of-squares x y)
  (+ (square x) (square y)))

(define (f a)
  (sum-of-squares (+ a 1) (* a 2)))

;; eager
;; (f 5)

;; (sum-of-squares (+ 5 1) (* 5 2))

;; (+ (square (+ 5 1)) (square (* 5 2)))

;; (+ (* (+ 5 1) (+ 5 1)) (* (* 5 2) (* 5 2)))

(define (f2 a)
  (let ((v #f)
        (r #f)
        (r2 #f)
        (x #f))
    (define (square!) (set! r (* x x)))
    (set! x (+ a 1))
    (square!)
    (set! r2 r)
    (set! x (* a 2))
    (square!)
    (sum-of-squares r2 r)))

;; Exercise 1.3. Define a procedure that takes three numbers as arguments and
;; returns the sum of the squares of the two larger numbers.


(define (f3 x y z)
  ;; (if (< x y)
  ;;
  ;;(if (< x z)
  ;;         (sum-of-squares y z)
  ;;         (sum-of-squares y (if (< y z) z))))

  (cond ((<= x y z) (sum-of-squares y z))
        ((<= x z y)(sum-of-squares y z))
        ((<= y x z)(sum-of-squares x z))
        ((<= y z x)(sum-of-squares x z))
        ((<= z x y)(sum-of-squares x y))
        ((<= z y x)(sum-of-squares x y))
        (else (error "wrong"))))

(define (mylength lis)
   (cond ((null? lis)
          0)
         (else
          (+ 1 (mylength (cdr lis))))))

;; f3, 1,2,3  => 13

  (f3
   1 2 3)

  (sum-of-squares 2 3)
